package com.zengqingfa.dubbo.mall.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.Lists;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zengqingfa.dubbo.mall.entity.UserAddress;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @fileName: OrderServiceImpl
 * @author: zengqf3
 * @date: 2021-4-12 15:02
 * @description:
 */
@Component
@Slf4j
public class OrderServiceImpl implements OrderService {

    // @Reference(url = "dubbo://localhost:20880")
    // @Reference(stub ="com.zengqingfa.dubbo.mall.service.UserServiceStub")
    // @Reference(stub = "true")
    @Reference
    UserService userService;

    /**
     * 初始化订单，查询用户的所有地址并返回
     * @param userId
     * @return
     */
    @Override
    @HystrixCommand(fallbackMethod = "fallback")
    public List<UserAddress> initOrder(String userId) {
        return userService.getUserAddressList(userId);
    }

    public List<UserAddress> fallback(String userId) {
        log.info("fallback ......userId={}",userId);
        ArrayList<UserAddress> list = Lists.newArrayList();
        list.add(new UserAddress(11, "fallback", "fallbakc", "fallback"));
        return list;
    }
}
